<span page-title>{{ "Repository Discovery" | translate }}</span>

<div class="row">
  <form ng-submit="discover()" name="discoveryForm" class="col-sm-5" role="form">
    <div bst-form-group label="{{ 'Repository Type' | translate }}">
      <select ng-model="discovery.contentType"
              ng-options="contentType.id as contentType.name for contentType in contentTypes"/>
    </div>

    <div bst-form-group ng-if="discovery.contentType === 'yum'"
         label="{{ 'URL to Discover' | translate }}">
      <input type="text" id="urlToDiscover"
             class="form-control"
             ng-pattern="/^(file:\/\/|http:\/\/|https:\/\/).+/"
             ng-model="discovery.url"
             ng-disabled="discovery.working"
             name="discoveryUrl"
             required/>
    </div>

    <div bst-form-group label="{{ 'Registry to Discover' | translate }}"  ng-if="discovery.contentType === 'docker'">
      <select required
              class="form-control"
              id="registry_type"
              name="registry_type"
              ng-model="discovery.registryType"
              ng-options="id as object.name for (id, object) in containerRegistries">
      </select>

      <input id="custom_registry_url"
             name="custom_registry_url"
             ng-model="discovery.customRegistryUrl"
             placeholder="Example: <private registry url>"
             ng-disabled="discovery.registryType !== 'custom'"/>
      <h6 translate>
        Choose one of the registry options to discover containers. To examine a private registry choose "Custom" and provide the url for the private registry.
      </h6>
    </div>

    <div bst-form-group
         label="{{ 'Username' | translate }}">
      <input type="text" id="upstreamUsername"
             class="form-control"
             ng-model="discovery.upstreamUsername"
             ng-disabled="discovery.working"
             ng-required="discovery.contentType === 'docker' && discovery.registryType === 'redhat'"
             name="upstreamUsername"/>
    </div>

    <div bst-form-group
         label="{{ 'Password' | translate }}">
      <input id="upstreamPassword"
             type="password"
             class="form-control"
             ng-model="discovery.upstreamPassword"
             ng-disabled="discovery.working"
             ng-required="discovery.contentType === 'docker' && discovery.registryType === 'redhat'"
             name="upstreamPassword"/>
    </div>

    <div bst-form-group ng-show="discovery.contentType === 'docker'"
         label="{{ 'Registry Search Parameter' | translate }}">
      <input type="text" id="registrySearch"
             class="form-control"
             ng-model="discovery.search"
             ng-disabled="discovery.working"
             placeholder="Default: * (search all)"
             name="discoverySearch"/>
    </div>

    <span class="input-group-btn">
      <button ng-show="!discovery.working && permitted('edit_products')"
              type="submit"
              class="btn btn-default">
        <span translate>Discover</span>
      </button>

      <button type="button"
              ng-show="discovery.working && permitted('edit_products')"
              ng-click="cancelDiscovery()"
              class="btn">
        <i class="fa fa-spinner fa-spin" ng-show="discovery.working"></i>
        <span translate>Cancel</span>
      </button>
    </span>
  </form>
</div>

<div data-extend-template="layouts/partials/table.html">
  <div data-block="search">
    <input type="text" class="form-control" stop-event="click"
           placeholder="{{ 'Filter' | translate }}"
           ng-model="tableFilter"/>
  </div>

  <div data-block="list-actions">
    <button class="btn btn-primary"
            translate
            ng-click="setupSelected()"
            ng-hide="denied('edit_products')"
            ng-disabled="discovery.working || table.numSelected === 0">
      Create Selected
    </button>
  </div>

  <span data-block="no-rows-message" translate>
    No discovered repositories.
  </span>

  <span data-block="no-search-results-message" translate>
    Your search returned zero results.
  </span>

  <div data-block="table">
    <table bst-table="table" class="table table-full table-bordered" ng-class="{'table-mask': discovery.working}">
      <thead>
        <tr bst-table-head row-select>
          <th bst-table-column="path" translate>Discovered Repository</th>
        </tr>
      </thead>

      <tbody>
        <tr bst-table-row ng-repeat="urlRow in filteredRows(tableFilter)" row-select="urlRow">
          <td bst-table-cell style="white-space:nowrap">{{ urlRow.path }}</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
